package actions

import actions.check.CheckAction
import actions.click.ClickAction
import actions.create.CreateAction
import actions.create.CreateMovieAction
import actions.save.SaveAction
import dsl.actions.ActionStructure

class ActionBuilder {

    static Action buildAction(ActionStructure actionStructure) {
        def actionString = actionStructure.action
        println actionStructure.item

        ActionType actionType = ActionType.getEnumItem(actionString)
        Action action = getAction(actionType, actionStructure.item)
        action.parameters = actionStructure.params
        action.setActionType(actionType)
        action.setItem(actionStructure.item)

        return action
    }

    private static Action getAction(ActionType actionType, String item) {
        switch (actionType) {
            case ActionType.CREATE:
                if (item.equalsIgnoreCase("movie")) {
                    return new CreateMovieAction()
                }
                return new CreateAction()

            case ActionType.CLICK:
                return new ClickAction()

            case ActionType.SAVE:
                return new SaveAction()

            case ActionType.CHECK:
                return new CheckAction()

            case ActionType.UPDATE:
                return null

            case ActionType.DELETE:
                return null

            default:
                return null
        }
    }

}
